import request from 'umi-request';
import moment from 'moment';

export async function queryResignationList(params = {},processingStatus) {
  let { current, hiredate, ...data} = params;
  let hiredateStart = hiredate?.length>1 ? moment(hiredate[0]).format('YYYY-MM-DD') : null;
  let hiredateEnd = hiredate?.length>1 ? moment(hiredate[1]).format('YYYY-MM-DD') : null;
  return request('/hr-ssc/api/api-admin/dimission/queryDimissionSettlementList', {
    method: 'get',
    params: {
      hiredateStart,
      hiredateEnd,
      processingStatus,
      pageNum: current,
      ...data
    },
  }).then((res) => {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
  });
}

export async function updateDimissionSettlement(params) {
  return request('/hr-ssc/api/api-admin/dimission/updateDimissionSettlement', {
    method: 'POST',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function dimissionSettlementBpm(id) {
  return request('/hr-ssc/api/api-admin/bpm/dimissionSettlementBpm', {
    method: 'GET',
    params: {id},
  }).then((res) => {
    return res;
  });
}


export async function deleteResignation(id = {}) {
  return request('/hr-ssc/api/api-admin/dimission/deleteDimission', {
    method: 'POST',
    data: {
      id: id,
    },
  }).then((res) => {
    const data = res.data;
    return res.flag;
  });
}

export async function updateDimissionSettlementStatus(params) {
  return request('/hr-ssc/api/api-admin/dimission/updateDimissionSettlementStatus', {
    method: 'POST',
    data: params,
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function deleteDimissionSettlement(id) {
  return request(`/hr-ssc/api/api-admin/dimission/deleteDimissionSettlement`, {
    method: 'delete',
    params: {id},
  }).then((res) => {
    return res;
  });
}
